home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / plugins / system_info.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  2.4 KB  |  80 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import logging
  20.  
  21. from checkbox.lib.safe import safe_md5sum
  22.  
  23. from checkbox.properties import String
  24. from checkbox.plugin import Plugin
  25.  
  26.  
  27. class SystemInfo(Plugin):
  28.  
  29.     # System ID to exchange information with the server.
  30.     system_id = String(required=False)
  31.  
  32.     def register(self, manager):
  33.         super(SystemInfo, self).register(manager)
  34.  
  35.         # System report should be generated early.
  36.         self._manager.reactor.call_on("report", self.report, -10)
  37.  
  38.         self._manager.reactor.call_on("gather-persist", self.gather_persist)
  39.  
  40.     def gather_persist(self, persist):
  41.         self.persist = persist.root_at("system_info")
  42.  
  43.     def report(self):
  44.         system_id = self.system_id or self.persist.get("system_id")
  45.         if not system_id:
  46.             computer = self._manager.registry.hal.computer
  47.             if not computer:
  48.                 return
  49.  
  50.             system = computer.system
  51.             if not system:
  52.                 return
  53.  
  54.             # Old versions of HAL didn't have the system namespace
  55.             if "hardware" in system:
  56.                 hardware = system.hardware
  57.             else:
  58.                 hardware = system
  59.  
  60.             fingerprint = safe_md5sum()
  61.             for field in [
  62.                     computer.info.product,
  63.                     computer.info.subsystem,
  64.                     system.product,
  65.                     system.vendor,
  66.                     system.formfactor,
  67.                     hardware.vendor,
  68.                     hardware.product]:
  69.                 fingerprint.update(str(field))
  70.  
  71.             system_id = fingerprint.hexdigest()
  72.             self.persist.set("system_id", system_id)
  73.  
  74.         message = system_id
  75.         logging.info("System ID: %s", message)
  76.         self._manager.reactor.fire("report-system_id", message)
  77.  
  78.  
  79. factory = SystemInfo
  80.